
/**
 * @Author: Liu, Yunfeng
 * @DateTime: 2021/7/27 21:19
 * @Description: TODO
 */
public class findSecondMinimumValue {
    int ans = -1;
    int rootvalue;
    public int findSecondMinimumValue(TreeNode root) {
        rootvalue = root.val;
        dfs(root);
        return ans;
    }

    public void dfs(TreeNode node) {
        if (node == null) {
            return;
        }
        if (ans != -1 && node.val >= ans) {
            return;
        }
        if (node.val > rootvalue) {
            ans = node.val;
        }
        dfs(node.left);
        dfs(node.right);
    }
}
